package com.lyl.momanapp.activity;

import android.app.Dialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.liji.circleimageview.CircleImageView;
import com.lyl.momanapp.R;
import com.lyl.momanapp.bean.URL;
import com.lyl.momanapp.util.view.MyBaseActivity;

import org.xutils.x;

/**
 * 名字 梁亚龙
 * 时间 2017/10/13.
 * QQ邮箱 503934353@qq.com
 */

public class UserInFoActivity extends MyBaseActivity {


    private ImageView mBackground;
    private CircleImageView mImg;
    private TextView mName;
    private LinearLayout mShopCar, mYouHui, mSeJi, mKeFu, mHelp, mSet, mQuanBu;
    private Dialog dialog;
    private View inflate;
    private LinearLayout mDaiFu;
    private LinearLayout mDaiFa;
    private LinearLayout mDaiSou;
    private LinearLayout mShouHou;

    @Override
    public void initUI() {
        setContentView(R.layout.activity_user_info);
        mBackground = ((ImageView) findViewById(R.id.user_info_background));
        mImg = ((CircleImageView) findViewById(R.id.user_info_img));
        mName = ((TextView) findViewById(R.id.user_info_name));
        mShopCar = ((LinearLayout) findViewById(R.id.user_info_shop_car));
        mYouHui = ((LinearLayout) findViewById(R.id.user_info_you_hui));
        mSeJi = ((LinearLayout) findViewById(R.id.user_info_see_ji));
        mKeFu = ((LinearLayout) findViewById(R.id.user_info_kefu));
        mHelp = ((LinearLayout) findViewById(R.id.user_info_help));
        mSet = ((LinearLayout) findViewById(R.id.user_info_set));
        mQuanBu = ((LinearLayout) findViewById(R.id.user_info_quan_bu));
        mDaiFu = ((LinearLayout) findViewById(R.id.user_info_dai_fu));
        mDaiFa = ((LinearLayout) findViewById(R.id.user_info_dai_fa));
        mDaiSou = ((LinearLayout) findViewById(R.id.user_info_dai_sou));
        mShouHou = ((LinearLayout) findViewById(R.id.user_info_shou_hou));
        ((ImageView) findViewById(R.id.fanhui)).setOnClickListener(this);
        ((ImageView) findViewById(R.id.zhuye)).setOnClickListener(this);
    }

    @Override
    public void initData() {
        mName.setText(URL.Userlogin.getResult().getNick_name());

        x.image().bind(mBackground, URL.Userlogin.getResult().getOriginal_avatar());
        // x.image().bind(mImg,URL.Userlogin.getResult().getAvatar());
        Glide.with(UserInFoActivity.this).load(URL.Userlogin.getResult().getAvatar()).into(mImg);
    }

    @Override
    public void addListeners() {
        mShopCar.setOnClickListener(this);
        mYouHui.setOnClickListener(this);
        mSeJi.setOnClickListener(this);
        mKeFu.setOnClickListener(this);
        mHelp.setOnClickListener(this);
        mSet.setOnClickListener(this);
        mQuanBu.setOnClickListener(this);
        mDaiFa.setOnClickListener(this);
        mDaiFu.setOnClickListener(this);
        mDaiSou.setOnClickListener(this);
        mShouHou.setOnClickListener(this);
        mImg.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.user_info_img: {
                startActivity(new Intent(UserInFoActivity.this, UserInfoDetailActivity.class));
            }
            break;
            case R.id.user_info_shop_car: {
                startActivity(new Intent(UserInFoActivity.this, ShopCarActivity.class));
            }
            break;
            case R.id.user_info_you_hui: {
                startActivity(new Intent(UserInFoActivity.this, UserCouponActivity.class));
            }
            break;
            case R.id.user_info_see_ji: {
                startActivity(new Intent(UserInFoActivity.this, UserSeJiActivity.class));
            }
            break;
            case R.id.user_info_quan_bu: {
                Intent intent = new Intent(UserInFoActivity.this, UserOrderActivity.class);
                Bundle bundle = new Bundle();
                //传递name参数为tinyphp
                bundle.putInt("name", 0);
                intent.putExtras(bundle);
                startActivity(intent);
            }
            break;
            case R.id.user_info_dai_fu: {
                Intent intent = new Intent(UserInFoActivity.this, UserOrderActivity.class);
                Bundle bundle = new Bundle();
                //传递name参数为tinyphp
                bundle.putInt("name", 1);
                intent.putExtras(bundle);
                startActivity(intent);
            }
            break;
            case R.id.user_info_dai_fa: {
                Intent intent = new Intent(UserInFoActivity.this, UserOrderActivity.class);
                Bundle bundle = new Bundle();
                //传递name参数为tinyphp
                bundle.putInt("name", 2);
                intent.putExtras(bundle);
                startActivity(intent);
            }
            break;
            case R.id.user_info_dai_sou: {
                Intent intent = new Intent(UserInFoActivity.this, UserOrderActivity.class);
                Bundle bundle = new Bundle();
                //传递name参数为tinyphp
                bundle.putInt("name", 3);
                intent.putExtras(bundle);
                startActivity(intent);
            }
            break;
            case R.id.user_info_shou_hou: {
                Intent intent = new Intent(UserInFoActivity.this, UserOrderActivity.class);
                Bundle bundle = new Bundle();
                //传递name参数为tinyphp
                bundle.putInt("name", 4);
                intent.putExtras(bundle);
                startActivity(intent);
            }
            break;
            case R.id.user_info_kefu: {
                showlianxi();
            }
            break;
            case R.id.fanhui: {
                finish();
            }
            break;
            case R.id.zhuye: {
                startActivity(new Intent(UserInFoActivity.this, MainActivity.class));
            }
            break;
            case R.id.user_info_set: {
                startActivity(new Intent(UserInFoActivity.this, SetActivity.class));
            }
            break;
            case R.id.user_info_help: {
                startActivity(new Intent(UserInFoActivity.this, HelpActivity.class));
            }
            break;
        }
    }

    public void showlianxi() {
        dialog = new Dialog(this, R.style.ActionSheetDialogStyle);
        //填充对话框的布局
        inflate = LayoutInflater.from(this).inflate(R.layout.item_lianxi, null);
        ((TextView) inflate.findViewById(R.id.lianxi_x)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.cancel();
            }
        });
        ((Button) inflate.findViewById(R.id.lianxi_call)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + "15538165120"));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                dialog.cancel();
            }
        });
        //将布局设置给Dialog
        dialog.setContentView(inflate);
        //获取当前Activity所在的窗体
        Window dialogWindow = dialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.CENTER);
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = getWindowManager().getDefaultDisplay().getWidth();
        lp.y = 20;//设置Dialog距离底部的距离
        //       将属性设置给窗体
        dialogWindow.setAttributes(lp);
        dialog.show();//显示对话框
    }
}
